package com.kgc.service.edu.controller;


import com.kgc.common.result.Result;
import com.kgc.service.edu.entity.Video;
import com.kgc.service.edu.service.VideoService;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author qf
 * @since 2021-03-07
 */

@CrossOrigin
@RestController
@RequestMapping("/edu/video")
public class VideoController {

    private final VideoService videoService;

    public VideoController(VideoService videoService) {
        this.videoService = videoService;
    }

    @PostMapping
    public Result addVideo(@RequestBody Video video) {
        boolean save = videoService.save(video);
        return save ? Result.ok() : Result.error();
    }

    @PutMapping
    public Result updateVideoById(@RequestBody Video video) {
        boolean update = videoService.updateById(video);
        return update ? Result.ok() : Result.error();
    }

    @GetMapping("{id}")
    public Result getVideoById(@PathVariable String id) {
        Video video = videoService.getById(id);
        return video != null ? Result.ok().setData("item", video) : Result.error();
    }

    @DeleteMapping("{id}")
    public Result delVideoById(@PathVariable String id){
        boolean del=videoService.delVideoById(id);
        return del?Result.ok():Result.error();
    }
}

